package com.swak.consistency.reliablemsg.manager.impl;

import org.springframework.beans.factory.annotation.Autowired;

import com.swak.consistency.reliablemsg.domain.ReliableMsgDTO;
import com.swak.consistency.reliablemsg.manager.ReliableMsgManager;
import com.swak.consistency.reliablemsg.storage.ReliableMsgLogStorage;
import com.swak.entity.Page;
import com.swak.entity.Parameters;
import com.swak.persistence.QueryCondition;
import com.swak.utils.StringUtils;

/**
 * ReliableMsgManager.
 * 
 * @author 618lf
 */
public class ReliableMsgManagerImpl implements ReliableMsgManager {

	@Autowired
	private ReliableMsgLogStorage storageService;

	@Override
	public Page<ReliableMsgDTO> logPage(ReliableMsgDTO query, Parameters param) {
		QueryCondition condition = new QueryCondition();
		if (StringUtils.isNotBlank(query.getQueue())) {
			condition.getCriteria().andLike("QUEUE", query.getQueue());
		}
		condition.setOrderByClause(param.orderBy("CREATE_TIME DESC"));
		return storageService.logPage(condition, param);
	}

	@Override
	public Page<ReliableMsgDTO> failPage(ReliableMsgDTO query, Parameters param) {
		QueryCondition condition = new QueryCondition();
		if (StringUtils.isNotBlank(query.getQueue())) {
			condition.getCriteria().andLike("QUEUE", query.getQueue());
		}
		return storageService.failPage(condition, param);
	}
}